import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Cache } from "../../cache/Cache";
import { FriendInfo } from "../../model/FriendInfo";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { BulkDeleteFriendsCellRendener } from "./cell/BulkDeleteFriendsCellRendener";
import { BulkDeleteDelCellRendener } from "./cell/BulkDeleteDelCellRendener";
import { MsgManager } from "../../manager/MsgManager";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { BulkDeleteFriendCellData } from "./cell/BulkDeleteFriendCellData";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GTileList } from "../../../../com/mui/controls/GTileList";
import { Vector } from "../../../../__AS3__/vec/Vector";
type int = number;
//class FriendBulkDeleteWindow
    
    export  class FriendBulkDeleteWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._cache = Cache.instance;
            this._vcFriendInfo = new Vector.<FriendInfo>();
            this._vcDelFriend = new Vector.<String>();
            this._aryDelIds = new Array<any>();
            setSize(402, 370);
            titleHeight = 26;
            title = Language.getString(40389);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createTextField(Language.getString(40390), 25, 40, 80, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(40391), 232, 40, 80, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createBg(19, 61, 202, 234, this);
            ObjCreate.createBg(225, 61, 157, 234, this);
            this._tileListFriends = ObjCreate.createTileList(20, 63, 198, 230, this);
            this._tileListFriends.rowHeight = 23;
            this._tileListFriends.columnWidth = 198;
            this._tileListFriends.setStyle("cellRenderer", BulkDeleteFriendsCellRendener);
            this._tileListDelete = ObjCreate.createTileList(227, 63, 152, 230, this);
            this._tileListDelete.rowHeight = 23;
            this._tileListDelete.columnWidth = 152;
            this._tileListDelete.setStyle("cellRenderer", BulkDeleteDelCellRendener);
            ObjCreate.createTextField(Language.getString(40392), 19, 302, 350, 20, this, GlobalStyle.textFormat6);
            this._btnBulkDelete = ObjCreate.createGButton(Language.getString(40393), 120, 327, 70, 26, this, "ButtonLarge");
            this._btnCancelDelete = ObjCreate.createGButton(Language.getString(40394), 212, 327, 70, 26, this, "ButtonLarge");
            this.addListeners();
            return;
        }

        /* internal  */addListeners(): void
        {
            this._btnBulkDelete.addEventListener(flash.events.MouseEvent.CLICK, this.onBulkDeleteClick);
            this._btnCancelDelete.addEventListener(flash.events.MouseEvent.CLICK, this.onCancelDeleteClick);
            return;
        }

        /* internal  */onBulkDeleteClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._aryDelIds.length == 0) 
            {
                MsgManager.showRollTipsMsg(Language.getString(40395));
                return;
            }
            Alert.show(Language.getString(40396), null, Alert.OK | Alert.CANCEL, null, this.onBulkAlertClose);
            return;
        }

        /* internal  */onBulkAlertClose(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.FriendBulkDel, this._aryDelIds));
            }
            return;
        }

        /* internal  */onCancelDeleteClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        public updateFriendList(): void
        {
            this._vcFriendInfo = Cache.instance.friend.getFriendList();
            this.updateView();
            return;
        }

        public addFriendToDel(arg1: FriendInfo): void
        {
            if (this._aryDelIds.length >= Cache.instance.friend.todayCanDeletefriendNum) 
            {
                MsgManager.showRollTipsMsg(Language.getString(40397));
                return;
            }
            if (this._vcDelFriend.indexOf(arg1.friendPlayerInfo.playerName) == -1) 
            {
                this._vcDelFriend.push(arg1.friendPlayerInfo.playerName);
            }
            this.updateView();
            return;
        }

        public cancelFriend(arg1: FriendInfo): void
        {
            var loc1=this._vcDelFriend.indexOf(arg1.friendPlayerInfo.playerName);
            if (loc1 >= 0) 
            {
                this._vcDelFriend.splice(loc1, 1);
            }
            this.updateView();
            return;
        }

        public updateView(): void
        {
            this._tileListFriends.dataProvider = this.getFriendsDataProvider();
            this._tileListDelete.dataProvider = this.getDelDataProvider();
            return;
        }

        /* internal  */getFriendsDataProvider(): DataProvider
        {
            var loc2=null;
            var loc3=null;
            var loc1=new Array<any>();
            var loc4=0;
            var loc5=this._vcFriendInfo;
            for(loc2 of loc5) 
            {
                if (this._cache.marry.playerMarry && this._cache.marry.playerMarry.mate) 
                {
                    if (this._cache.marry.playerMarry.mate.entityId.id == loc2.friendPlayerInfo.playerId) 
                    {
                        continue;
                    }
                }
                loc3 = new BulkDeleteFriendCellData();
                loc3.friendInfo = loc2;
                if (this._vcDelFriend.indexOf(loc2.friendPlayerInfo.playerName) > -1) 
                {
                    loc3.isAddToDel = true;
                }
                else 
                {
                    loc3.isAddToDel = false;
                }
                loc1.push(loc3);
            }
            return new DataProvider(loc1);
        }

        /* internal  */getDelDataProvider(): DataProvider
        {
            var loc2=null;
            var loc1=new Array<any>();
            this._aryDelIds = new Array<any>();
            var loc3=0;
            var loc4=this._vcFriendInfo;
            for(loc2 of loc4) 
            {
                if (!(this._vcDelFriend.indexOf(loc2.friendPlayerInfo.playerName) >= 0)) 
                {
                    continue;
                }
                loc1.push(loc2);
                this._aryDelIds.push(loc2.recordId);
            }
            return new DataProvider(loc1);
        }

        /* internal */ /* var */_btnBulkDelete: GButton;

        /* internal */ /* var */_btnCancelDelete: GButton;

        /* internal */ /* var */_tileListFriends: GTileList;

        /* internal */ /* var */_tileListDelete: GTileList;

        /* internal */ /* var */_cache: Cache;

        /* internal */ /* var */_vcFriendInfo: Vector.<FriendInfo>;

        /* internal */ /* var */_vcDelFriend: Vector.<String>;

        /* internal */ /* var */_aryDelIds: Array<any>;
    }
